/* eslint-disable no-unused-vars */
async function module (moduleName) {
  const jsreport = require('jsreport-proxy')
  return jsreport.module(moduleName)
}

function toJS (data) {
  function jsStringEscape (string) {
    return ('' + string).replace(/["'\\\n\r\u2028\u2029]/g, function (character) {
      // Escape all characters not included in SingleStringCharacters and
      // DoubleStringCharacters on
      // http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
      switch (character) {
        case '"':
        case "'":
        case '\\':
          return '\\' + character
          // Four possible LineTerminator characters need to be escaped:
        case '\n':
          return '\\n'
        case '\r':
          return '\\r'
        case '\u2028':
          return '\\u2028'
        case '\u2029':
          return '\\u2029'
      }
    })
  }

  const validDataStr = jsStringEscape(JSON.stringify(data))
  return `JSON.parse('${validDataStr}')`
}
